package dao.impl;

import dao.BaseDao;
import dao.StudentDao;
import com.entity.Student;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class StudentDaoImpl extends BaseDao implements StudentDao {

    @Override
    public int login(String name, String phong) {
        return 0;
    }
    @Override
    public int delete(int studentno) {
        String sql="delete from student where studentno=?";
        Object[]params={studentno};
        int count=this.executeUpdate(sql,params);
        return count;
    }

    @Override
    public List<Student> findAll() {
        String sql = "SELECT studentno,studentname,address,borndate FROM student";
        ResultSet rs = this.executeQuery(sql);
        ArrayList<Student>stuList = new ArrayList<>();
        try {
            while (rs.next()) {
                String studentNo = rs.getString(1);
                String studentName = rs.getString(2);
                String address = rs.getString(3);
                Date bornDate = rs.getDate(4);
                Student student = new Student(studentNo, studentName, bornDate,address);
                stuList.add(student);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            this.closeAll(null,null,rs);
        }
        return stuList;
    }

}
